import http from '@/utils/http'
import convert from '@/utils/model-convert'
import {SearchArgument} from '@/models/customer/customer/survey-templet'

const URL = '/rest/customer/customer/survey-templets'
const OPERATE_URL = '/rest/customer/customer/survey-templets/{id}'

export default {
  list ({search}, cb) {
    http.get(URL, {
      params: convert.toJson(search, SearchArgument)
    }).then(response => cb(response)).catch(trace => cb(trace.response))
  },
  uploadImg ({form}, cb) {
    let formData = new FormData()
    formData.append('imageName', form.imageName)
    formData.append('imgFile', form.imgFile)
    formData.append('token', form.token)
    http.post(URL, formData, {
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    }).then(response => cb(response)).catch(trace => cb(trace.response))
  },
  delete ({id}, cb) {
    http.delete(OPERATE_URL.replace('{id}', id))
      .then(response => cb(response)).catch(trace => cb(trace.response))
  }
}
